<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <title>
        收费项目添加
    </title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" th:href="@{/css/main.css}" href="${pageContext.request.contextPath }/statics/css/main.css"
          media="all">
    <script type="text/javascript" th:src="@{/lib/loading/okLoading.js}"
            src="${pageContext.request.contextPath }/statics/lib/loading/okLoading.js"></script>
</head>
<body>
<div class="x-nav">
            <span class="layui-breadcrumb">
              <a><cite>首页</cite></a>
              <a><cite>收费添加</cite></a>
            </span>
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right"
       href="javascript:location.replace(location.href);" title="刷新"><i class="layui-icon"
                                                                        style="line-height:30px">ဂ</i></a>
</div>
<div class="x-body">
    <form class="layui-form layui-form-pane" action="" id="add">
        <div class="layui-tab layui-tab-brief" lay-filter="docDemoTabBrief">
            <div class="layui-tab-content">
                <div class="layui-tab-item layui-show">
                    <input type="hidden" name="id" value="${param.id}">
                    <div class="layui-form-item">
                        <label class="layui-form-label">
                            <span class='x-red'>*</span>收费编号
                        </label>
                        <div class="layui-input-block">
                            <input type="text" name="feeNo" autocomplete="off" placeholder="请填写收费编号"
                                   class="layui-input" value="" disabled>
                        </div>
                    </div>

                    <div class="layui-form-item">
                        <label class="layui-form-label">
                            <span class='x-red'>*</span>项目名称
                        </label>
                        <div class="layui-input-block">
                            <input type="text" name="feeName" autocomplete="off" placeholder="请填写项目名称"
                                   class="layui-input" value="">
                        </div>
                    </div>

                    <div class="layui-form-item">
                        <label class="layui-form-label">
                            <span class='x-red'>*</span>收费金额(￥)
                        </label>
                        <div class="layui-input-block">
                            <input type="text" name="feeMoney" autocomplete="off" placeholder="请填写收费金额(￥)"
                                   class="layui-input" value="">
                        </div>
                    </div>

                    <div class="layui-form-item">
                        <label class="layui-form-label">
                            <span class='x-red'>*</span>收费规则
                        </label>
                        <div class="layui-input-block">
                            <input type="hidden" value="" name="fee_rule" id="fee_rule"/>
                            <select name="feeRule" id="feeRule" disabled>
                                <option value="0">---请选择收费规则---</option>
                                <option value="1">按时收费</option>
                                <option value="2">按次收费</option>
                                <option value="3">按白天夜间段收费</option>
                                <option value="4">按设定时间收费</option>
                            </select>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">
                            <span class='x-red'>*</span>车辆类型
                        </label>
                        <div class="layui-input-block">
                            <input type="hidden" value="" name="fee_type" id="fee_type"/>
                            <select name="feeType" id="feeType" disabled>
                                <option value="0">---请选择车辆类型---</option>
                                <option value="1">家用小汽车</option>
                                <option value="2">客车</option>
                                <option value="3">货车</option>
                                <option value="4">三轮车</option>
                            </select>
                        </div>
                    </div>

                    <div class="layui-form-item">
                        <button class="layui-btn" type="button" lay-filter="add" lay-submit="">
                            保存
                        </button>
                    </div>

                    <div style="height:100px;"></div>
                </div>
            </div>
        </div>
    </form>
</div>
<script th:src="@{/lib/layui/layui.js}" src="${pageContext.request.contextPath }/statics/lib/layui/layui.js"
        charset="utf-8"></script>
<script th:src="@{/js/jquery.min.js}" src="${pageContext.request.contextPath }/statics/js/jquery.min.js"></script>
<script th:src="@{/js/x-layui.js}" src="${pageContext.request.contextPath }/statics/js/x-layui.js"
        charset="utf-8"></script>

<script>
    if ($("input[name='id']").val() != "") {    //根据id查询数据
        var id = $("input[name='id']").val()
        $.get("/fee/" + id, function (data) {
            $("input[name='feeNo']").val(data.data.feeNo);
            $("input[name='feeName']").val(data.data.feeName);
            $("input[name='feeMoney']").val(data.data.feeMoney);
            $("input[name='fee_rule']").val(data.data.feeRule);
            selectByOptionTxt($("select[name='feeRule']"), data.data.feeRule)
            $("input[name='fee_type']").val(data.data.feeType);
            selectByOptionTxt($("select[name='feeType']"), data.data.feeType)
            $("input[name='modifyDate']").val(data.data.modifyDate);
        })
    }

    function selectByOptionTxt(obj, txt) {
        var optionArr = $(obj).find("option");
        for (var i = 0; i < optionArr.length; i++) {
            if (optionArr.eq(i).val() == txt) {
                $(obj).val(optionArr.eq(i).val());
                break;
            }
        }
    }

    layui.use(['laydate', 'element', 'layer', 'form'], function () {
        $ = layui.jquery;//jquery
        lement = layui.element();//面包导航
        layer = layui.layer;//弹出层
        form = layui.form();
        laydate = layui.laydate;//日期插件
        okLoading.close($);
        form.render();


        //监听提交
        form.on('submit(add)', function (data) {
            var feeName = $("input[name='feeName']").val();

            if (feeName == "") {
                layer.msg('项目名称不能为空', {icon: 5, time: 2000});
                return false;
            }

            var data = data.field;
            if ($("input[name='id']").val() != "") {    //修改
                $.ajax({
                    type: "put",
                    url: "/fee/update",
                    data: data,
                    dataType: "json",
                    success: function (data) {
                        console.log(data)
                        if (data.data == true) {
                            layer.msg(data.msg, {icon: 6, time: 2000}, function () {
                                window.parent.location.reload();
                                var index = parent.layer.getFrameIndex(window.name);
                                parent.layer.close(index);
                            });
                            return false;
                        }
                        else {
                            layer.msg(data.msg, {icon: 5, time: 2000});
                            return false;
                        }
                    }
                });
            }

            if ($("input[name='id']").val() == "") {    //增加
                $.ajax({
                    type: "post",
                    url: "/fee/add",
                    data: data,
                    dataType: "json",
                    success: function (data) {
                        console.log(data)
                        if (data.data == true) {
                            layer.msg(data.msg, {icon: 6, time: 2000}, function () {
                                window.parent.location.reload();
                                var index = parent.layer.getFrameIndex(window.name);
                                parent.layer.close(index);
                            });
                            return false;
                        }
                        else {
                            layer.msg(data.msg, {icon: 5, time: 2000});
                            return false;
                        }
                    }
                });
            }

        });

    })
</script>
<!--栏目缩略图上传-->
<script>
    function upload() {
        var formData = new FormData();
        formData.append('images', $('#previewImg')[0].files[0]);
        //console.log(formData);
        layer.msg('图片上传中', {icon: 16});
        $.ajax({
            type: "post",
            processData: false,
            contentType: false,
            url: "xxx",
            data: formData,
            success: function (data) {
                if (data.status == 1) {
                    console.log(data.image_name);
                    layer.closeAll('loading');
                    //layer.msg(data.info,{icon:1,time:1000});
                    $("#pimages").attr('src', data.image_name);
                    $("#avatar").val(data.image_name);
                    $(".imgs").show();
                    return false;
                } else {
                    layer.msg(data.info, {icon: 2, time: 1000});
                }
            }
        });
    }
</script>

</body>
</html>